/*
* Copyright 2025 NXP
* NXP Proprietary. This software is owned or controlled by NXP and may only be used strictly in
* accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
* activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms.  If you do not agree to be bound by the applicable license
* terms, then you may not retain, install, activate or otherwise use the software.
*/

#include "lvgl.h"
#include <stdio.h>
#include "gui_guider.h"
#include "events_init.h"
#include "widgets_init.h"
#include "nrf_process.h"
#include "custom.h"

static void massage_btn_1_pressed_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_PRESSED:
    {
        nrf_para.nrf.send_cmd = MASSAGE_CMD;
        nrf_para.nrf.start_send_flag = true;
        break;
    }
    default:
        break;
    }
}


void setup_scr_massage_onoff(lv_ui *ui)
{

    lv_group_t * main_group = lv_group_create();//创建一个组
    lv_indev_set_group(indev_keypad, main_group);

    //Write codes massage_onoff
    ui->massage_onoff = lv_obj_create(NULL);
    lv_obj_set_size(ui->massage_onoff, 240, 320);
    lv_obj_set_scrollbar_mode(ui->massage_onoff, LV_SCROLLBAR_MODE_OFF);

    //Write style for massage_onoff, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
    lv_obj_set_style_bg_opa(ui->massage_onoff, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui->massage_onoff, lv_color_hex(guider_ui.color.backlight), LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_grad_dir(ui->massage_onoff, LV_GRAD_DIR_NONE, LV_PART_MAIN|LV_STATE_DEFAULT);

    //Write codes massage_onoff_btn_1
    ui->massage_onoff_btn_1 = lv_btn_create(ui->massage_onoff);
    ui->massage_onoff_btn_1_label = lv_label_create(ui->massage_onoff_btn_1);
    if (backlight.bits.msg_on_off) {
        lv_label_set_text(ui->massage_onoff_btn_1_label, "OFF");
    } else {
        lv_label_set_text(ui->massage_onoff_btn_1_label, "ON");
    }

    lv_label_set_long_mode(ui->massage_onoff_btn_1_label, LV_LABEL_LONG_WRAP);
    lv_obj_align(ui->massage_onoff_btn_1_label, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_style_pad_all(ui->massage_onoff_btn_1, 0, LV_STATE_DEFAULT);
    lv_obj_set_width(ui->massage_onoff_btn_1_label, LV_PCT(100));
    lv_obj_set_pos(ui->massage_onoff_btn_1, 68, 111);
    lv_obj_set_size(ui->massage_onoff_btn_1, 99, 99);
    lv_obj_add_flag(ui->massage_onoff_btn_1, LV_OBJ_FLAG_CLICK_FOCUSABLE);

    //Write style for massage_onoff_btn_1, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
    lv_obj_set_style_bg_opa(ui->massage_onoff_btn_1, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui->massage_onoff_btn_1, lv_color_hex(0x1f5f94), LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_grad_dir(ui->massage_onoff_btn_1, LV_GRAD_DIR_NONE, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui->massage_onoff_btn_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_radius(ui->massage_onoff_btn_1, 5, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(ui->massage_onoff_btn_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(ui->massage_onoff_btn_1, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui->massage_onoff_btn_1, &lv_font_montserrat_14, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(ui->massage_onoff_btn_1, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(ui->massage_onoff_btn_1, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);

    lv_group_add_obj(main_group, ui->massage_onoff_btn_1);
    //The custom code of massage_onoff.
    lv_obj_add_event_cb(ui->massage_onoff_btn_1, massage_btn_1_pressed_cb, LV_EVENT_ALL, ui);

    //Update current screen layout.
    lv_obj_update_layout(ui->massage_onoff);

}
